home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bisonpcb.zip / TGRAM.C < prev    next >
C/C++ Source or Header  |  1987-09-18  |  11KB  |  477 lines

  1.  
  2. /*  A Bison parser, made from tgram.y  */
  3.  
  4. #define    TERM    258
  5. #define    TTERM    3
  6. #define    UMINUS    259
  7. #define    TUMINUS    11
  8.  
  9. #include "tgram.att"
  10. #include <stdio.h>
  11.  
  12.  
  13.  
  14. #define    YYFINAL        20
  15. #define    YYFLAG        -32768
  16. #define    YYNTBASE    12
  17.  
  18. #define YYTRANSLATE(x) (yytranslate[x])
  19.  
  20. static char yytranslate[] = {     0,
  21.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  22.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  23.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  24.      2,     2,     2,     2,     2,     2,     2,     2,     2,     4,
  25.      5,     9,     7,     2,     8,     2,     2,     2,     2,     2,
  26.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  27.      6,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  28.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  29.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  30.      2,    10,     2,     2,     2,     2,     2,     2,     2,     2,
  31.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  32.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  33.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  34.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  35.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  36.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  37.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  38.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  39.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  40.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  41.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  42.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  43.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  44.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  45.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  46.      2,     2,     2,     2,     2,     1,     2,     3,    11
  47. };
  48.  
  49. static short yyprhs[] = {     0,
  50.      0,     4,     8,    12,    16,    17,    22,    25,    27
  51. };
  52.  
  53. static short yyrhs[] = {    12,
  54.      7,    12,     0,    12,     8,    12,     0,    12,     9,    12,
  55.      0,    12,    10,    12,     0,     0,     4,    13,    12,     5,
  56.      0,     8,    12,     0,     3,     0,    12,     6,    12,     0
  57. };
  58.  
  59. static short yystos[] = {     0,
  60.      3,     4,     8,    12,    13,    12,     6,     7,     8,     9,
  61.     10,    12,    12,    12,    12,    12,    12,     5,     0,     0
  62. };
  63.  
  64. static short yyrline[] = {     0,
  65.     14,    15,    16,    17,    18,    18,    19,    20,    21
  66. };
  67.  
  68. static char * yytname[] = {     0,
  69. "error","$illegal.","TERM","'('","')'","'='","'+'","'-'","'*'","'\\\\'",
  70. "UMINUS","expr"
  71. };
  72.  
  73. static short yyr1[] = {     0,
  74.     12,    12,    12,    12,    13,    12,    12,    12,    12
  75. };
  76.  
  77. static short yyr2[] = {     0,
  78.      3,     3,     3,     3,     0,     4,     2,     1,     3
  79. };
  80.  
  81. static short yydefact[] = {     0,
  82.      8,     5,     0,     0,     0,     7,     0,     0,     0,     0,
  83.      0,     0,     9,     1,     2,     3,     4,     6,     0,     0
  84. };
  85.  
  86. static short yydefgoto[] = {     4,
  87.      5
  88. };
  89.  
  90. static short yypact[] = {    23,
  91. -32768,-32768,    23,     0,    23,-32768,    23,    23,    23,    23,
  92.     23,    15,    -5,    19,-32768,-32768,-32768,-32768,    12,-32768
  93. };
  94.  
  95. static short yypgoto[] = {     8,
  96. -32768
  97. };
  98.  
  99.  
  100. #define    YYLAST        31
  101.  
  102.  
  103. static short yytable[] = {    19,
  104.      7,     8,     9,    10,    11,     7,     8,     9,    10,    11,
  105.      6,    20,    12,     0,    13,    14,    15,    16,    17,    18,
  106.      7,     8,     9,    10,    11,     1,     2,    10,    11,     0,
  107.      3
  108. };
  109.  
  110. static short yycheck[] = {     0,
  111.      6,     7,     8,     9,    10,     6,     7,     8,     9,    10,
  112.      3,     0,     5,    -1,     7,     8,     9,    10,    11,     5,
  113.      6,     7,     8,     9,    10,     3,     4,     9,    10,    -1,
  114.      8
  115. };
  116. #define YYPURE 1
  117.  
  118.  
  119. extern int timeclock;
  120.  
  121.  
  122. int yyerror;        /*  Yyerror and yycost are set by guards.    */
  123. int yycost;        /*  If yyerror is set to a nonzero value by a    */
  124.             /*  guard, the reduction with which the guard    */
  125.             /*  is associated is not performed, and the    */
  126.             /*  error recovery mechanism is invoked.    */
  127.             /*  Yycost indicates the cost of performing    */
  128.             /*  the reduction given the attributes of the    */
  129.             /*  symbols.                    */
  130.  
  131.  
  132. #define    YYACCEPT    return (0)
  133. #define    YYABORT        return (1)
  134.  
  135.  
  136. /*  YYMAXDEPTH indicates the size of the parser's state and value    */
  137. /*  stacks.                                */
  138.  
  139. #ifndef    YYMAXDEPTH
  140. #define    YYMAXDEPTH    500
  141. #endif
  142.  
  143. /*  YYMAXRULES must be at least as large as the number of rules that    */
  144. /*  could be placed in the rule queue.  That number could be determined    */
  145. /*  from the grammar and the size of the stack, but, as yet, it is not.    */
  146.  
  147. #ifndef    YYMAXRULES
  148. #define    YYMAXRULES    100
  149. #endif
  150.  
  151. #ifndef    YYMAXBACKUP
  152. #define YYMAXBACKUP    100
  153. #endif
  154.  
  155.  
  156. short    yyss[YYMAXDEPTH];    /*  the state stack            */
  157. YYSTYPE    yyvs[YYMAXDEPTH];    /*  the semantic value stack        */
  158. YYLTYPE yyls[YYMAXDEPTH];    /*  the location stack            */
  159. short    yyrq[YYMAXRULES];    /*  the rule queue            */
  160. int    yychar;            /*  the lookahead symbol        */
  161.  
  162. YYSTYPE    yylval;            /*  the semantic value of the        */
  163.                 /*  lookahead symbol            */
  164.  
  165. YYSTYPE yytval;            /*  the semantic value for the state    */
  166.                 /*  at the top of the state stack.    */
  167.  
  168. YYSTYPE yyval;            /*  the variable used to return        */
  169.                 /*  semantic values from the action    */
  170.                 /*  routines                */
  171.  
  172. YYLTYPE yylloc;        /*  location data for the lookahead    */
  173.                 /*  symbol                */
  174.  
  175. YYLTYPE yytloc;        /*  location data for the state at the    */
  176.                 /*  top of the state stack        */
  177.  
  178.  
  179. int    yynunlexed;
  180. short    yyunchar[YYMAXBACKUP];
  181. YYSTYPE    yyunval[YYMAXBACKUP];
  182. YYLTYPE yyunloc[YYMAXBACKUP];
  183.  
  184. short *yygssp;            /*  a pointer to the top of the state    */
  185.                 /*  stack; only set during error    */
  186.                 /*  recovery.                */
  187.  
  188. YYSTYPE *yygvsp;        /*  a pointer to the top of the value    */
  189.                 /*  stack; only set during error    */
  190.                 /*  recovery.                */
  191.  
  192. YYLTYPE *yyglsp;        /*  a pointer to the top of the        */
  193.                 /*  location stack; only set during    */
  194.                 /*  error recovery.            */
  195.  
  196.  
  197. /*  Yyget is an interface between the parser and the lexical analyzer.    */
  198. /*  It is costly to provide such an interface, but it avoids requiring    */
  199. /*  the lexical analyzer to be able to back up the scan.        */
  200.  
  201. yyget()
  202. {
  203.   if (yynunlexed > 0)
  204.     {
  205.       yynunlexed--;
  206.       yychar = yyunchar[yynunlexed];
  207.       yylval = yyunval[yynunlexed];
  208.       yylloc = yyunloc[yynunlexed];
  209.     }
  210.   else if (yychar <= 0)
  211.     yychar = 0;
  212.   else
  213.     {
  214.       yychar = yylex();
  215.       if (yychar < 0)
  216.     yychar = 0;
  217.       else yychar = YYTRANSLATE(yychar);
  218.     }
  219. }
  220.  
  221.  
  222.  
  223. yyunlex(chr, val, loc)
  224. int chr;
  225. YYSTYPE val;
  226. YYLTYPE loc;
  227. {
  228.   yyunchar[yynunlexed] = chr;
  229.   yyunval[yynunlexed] = val;
  230.   yyunloc[yynunlexed] = loc;
  231.   yynunlexed++;
  232. }
  233.  
  234.  
  235.  
  236. yyrestore(first, last)
  237. register short *first;
  238. register short *last;
  239. {
  240.   register short *ssp;
  241.   register short *rp;
  242.   register int symbol;
  243.   register int state;
  244.   register int tvalsaved;
  245.  
  246.   ssp = yygssp;
  247.   yyunlex(yychar, yylval, yylloc);
  248.  
  249.   tvalsaved = 0;
  250.   while (first != last)
  251.     {
  252.       symbol = yystos[*ssp];
  253.       if (symbol < YYNTBASE)
  254.     {
  255.       yyunlex(symbol, yytval, yytloc);
  256.       tvalsaved = 1;
  257.       ssp--;
  258.     }
  259.  
  260.       ssp--;
  261.  
  262.       if (first == yyrq)
  263.     first = yyrq + YYMAXRULES;
  264.  
  265.       first--;
  266.  
  267.       for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++)
  268.     {
  269.       if (symbol < YYNTBASE)
  270.         state = yytable[yypact[*ssp] + symbol];
  271.       else
  272.         {
  273.           state = yypgoto[symbol - YYNTBASE] + *ssp;
  274.  
  275.           if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp)
  276.         state = yytable[state];
  277.           else
  278.         state = yydefgoto[symbol - YYNTBASE];
  279.         }
  280.  
  281.       *++ssp = state;
  282.     }
  283.     }
  284.  
  285.   if ( ! tvalsaved && ssp > yyss)
  286.     {
  287.       yy